package com.huawei;

import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;


//有待优化，写算法题，尽量不要用正则
public class HJ020 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        while(scanner.hasNextLine()){
            String input = scanner.nextLine();
            if(input.isEmpty()){
                break;
            }
            boolean flag = checkAll(input);
            if(flag){
                System.out.println("OK");
            }else{
                System.out.println("NG");
            }
        }
    }


    public static boolean checkAll(String input){
        return checkLength(input) && checkThreeType(input) && checkRepeat(input);
    }

    public static boolean checkLength(String input){
        if(input.length()<=8){
            return false;
        }
        return true;
    }


    public static boolean checkThreeType(String input){
        String[] split = input.split("");
        int typeCount = 0;
        int[] charType = new int[4];
        for(String s:split){
            if(s.matches("[a-z]")){
                charType[0]=1;
            }
            if(s.matches("[A-Z]")){
                charType[1]=1;
            }
            if(s.matches("[0-9]")){
                charType[2]=1;
            }
            if(s.matches("\\W")){
                charType[3]=1;
            }
        }
        for (int type : charType) {
            if(1==type){
                typeCount++;
            }
        }
        if(typeCount<3){
            return false;
        }
        return true;
    }


    public static boolean checkRepeat(String input){
       //找出相邻的三个词组成的字符串数组
        Set<String> set = new HashSet<>();
        for (int i = 0; i < input.length() - 2; i++) {
            if (!set.add(input.substring(i, i + 3))) {
                return false;
            }
        }
        return true;
    }
}
